package com.dragon.repository.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.repository.config.annotation.DataScope;
import com.dragon.repository.entity.AttendanceLeave;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dragon.repository.entity.Produce;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 请假表 Mapper 接口
 * </p>
 *
 * @author sy
 * @since 2023-07-20
 */
@Mapper
public interface AttendanceLeaveMapper extends BaseMapper<AttendanceLeave> {

    /**
     * 分页列表
     * @param leavePage
     * @param wrapper
     * @return
     */
    @Select("select M.*, da2.username as toUsername from (select dal.*,da.username as username from dragon_attendance_leave dal " +
            "left join dragon_admin da on dal.admin_id = da.id)M " +
            "left join dragon_admin da2 on M.to_id = da2.id  " +
            "${ew.customSqlSegment} ")
    Page<AttendanceLeave> selectLeavePage(Page<AttendanceLeave> leavePage, @Param(Constants.WRAPPER) QueryWrapper<AttendanceLeave> wrapper);

    /**
     * 单个详情
     * @param id
     * @return
     */
    @Select("select M.*, da2.username as toUsername from " +
            "(select dal.*,da.username as username, da.img as userImg from dragon_attendance_leave dal " +
            "left join dragon_admin da on dal.admin_id = da.id)M " +
            "left join dragon_admin da2 on M.to_id = da2.id " +
            "where M.id = #{id} ")
    AttendanceLeave selectDetail(Integer id);


    /**
     * 请假列表
     * @param leavePage
     * @param wrapper
     * @return
     */
    @Select("select M.*, da2.username as toUsername from " +
            "(select dal.*,da.username as username, ddd.name as leaveTypeName from dragon_attendance_leave dal " +
            "left join dragon_admin da on dal.admin_id = da.id " +
            "left join dragon_dictsort_detail ddd on dal.leave_type = ddd.`value` and ddd.code_type = 'leaveType')M " +
            "left join dragon_admin da2 on M.to_id = da2.id " +
            "${ew.customSqlSegment} ")
    List<AttendanceLeave> selectLeaveList(@Param(Constants.WRAPPER) QueryWrapper<AttendanceLeave> wrapper);

}
